package com.dc.project.system.controller;

import com.dc.common.validated.InsertGroup;
import com.dc.common.validated.QueryPageGroup;
import com.dc.common.validated.UpdateGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.system.dto.SysRoleDeptDto;
import com.dc.project.system.entity.SysRoleDept;
import com.dc.project.system.service.SysRoleDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 角色部门关联表(SysRoleDept)表控制层
 *
 * @author zhuangcy
 * @since 2021-06-04 17:09:08
 */
@RestController
@RequestMapping("sysRoleDept")
@Api(tags = "角色部门关联表")
public class SysRoleDeptController {
    /**
     * 服务对象
     */
    @Autowired
    private SysRoleDeptService sysRoleDeptService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    @RequiresPermissions("system:sysRoleDept:query")
    public ResultVo get(@PathVariable Serializable id) {
        return this.sysRoleDeptService.queryById(id);
    }

    /**
     * 分页查询角色部门关联表
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询角色部门关联表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
    @RequiresPermissions("system:sysRoleDept:query")
    public ResultVo listPage(@Validated(QueryPageGroup.class) SysRoleDeptDto dto) {
        return this.sysRoleDeptService.queryByPage(dto);
    }

    /**
     * 新增角色部门关联表
     *
     * @param sysRoleDept
     * @return
     */
    @PostMapping
    @ApiOperation("新增角色部门关联表")
    @RequiresPermissions("system:sysRoleDept:add")
    public ResultVo add(@Validated(value = {InsertGroup.class}) @RequestBody SysRoleDept sysRoleDept) {
        return this.sysRoleDeptService.add(sysRoleDept);
    }

    /**
     * 编辑角色部门关联表
     *
     * @param sysRoleDept
     * @return
     */
    @PutMapping
    @ApiOperation("编辑角色部门关联表")
    @RequiresPermissions("system:sysRoleDept:edit")
    public ResultVo edit(@Validated(value = {UpdateGroup.class}) @RequestBody SysRoleDept sysRoleDept) {
        return this.sysRoleDeptService.edit(sysRoleDept);
    }

    /**
     * 根据主键删除角色部门关联表
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除角色部门关联表")
    @RequiresPermissions("system:sysRoleDept:delete")
    public ResultVo delete(@PathVariable Serializable id) {
        return this.sysRoleDeptService.delete(id);
    }

}